<?php
/**
 * Author: Hancock
 * Email: 84622365@qq.com
 * Date: 7/18/2016
 * Des: 系统管理员
 */
defined('INHkMvc') or exit('Access Invalid!');

class App_member_login_logModel extends AppModel
{
    /**
     * 添加日志
     * @param $data
     * @return bool
     */
    public function addLog($data)
    {
        return $this->insert($this->filterParams($data));
    }
    protected function filterParams($params)
    {
        foreach ($params as $key => &$param) {
            if ($key == 'member_id' || $key == 'status') {
                $param = intval($param);
            } elseif ($key == 'login_ip') {
                $length = explode('.', $param);
                if(count($length)!=4){
                    $param = get_client_ip();
                }
                foreach($length as $v){
                    if(intval($v)>255){
                        $param = get_client_ip();
                        break;
                    }
                }
            } elseif ($key == 'login_time') {
                $param = intval($param);
                if (strlen($param) != 10) {
                    $param = time();
                }
            } elseif ($key == 'content') {
                $param = trim($param);
            } elseif ($key == 'error') {
                $param = ($param === 1) ? 1 : 0;
            } elseif ($key == 'type') {
                $param = (intval($param) > 3) ? 0 : intval($param);
            }
        }
        return $params;
    }
}
